package com.huadao.cart_ccs.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import com.huadao.cart_ccs.R;

import java.util.HashMap;
import java.util.Map;

public class DialogUtil {
    private Context context;

    public DialogUtil(Context context) {
        this.context = context;
    }

    public void showConfirmDialog(String message, DialogInterface.OnClickListener dialogListener){
        new AlertDialog.Builder(context)
//                .setTitle(context.getString(R.string.confirmTitle))
                .setMessage(message)
                .setPositiveButton(context.getText(R.string.yes), dialogListener)
                .setNegativeButton(context.getText(R.string.cancel), dialogListener)
                .show();
    }

    public void showMessageDialog(String message,DialogInterface.OnClickListener dialogListener){
        new AlertDialog.Builder(context)
                .setMessage(message)
                .setPositiveButton(context.getText(R.string.yes), dialogListener)
                .show();
    }

    public void setParamsDialog(final SetParamCallBack dialogListener){
        LayoutInflater inflater = LayoutInflater.from(context);
        View view=inflater.inflate(R.layout.dialog_setparams,null);
        final EditText et_temperature=view.findViewById(R.id.et_temperature);
        final EditText et_CO2_concentration=view.findViewById(R.id.et_CO2_concentration);
        final AlertDialog alertDialog=new AlertDialog.Builder(context, android.R.style.Theme_Holo_Light_Dialog_NoActionBar)
                .setTitle("设置培养箱参数")
                .setView(view)
                .setPositiveButton(context.getText(R.string.yes), null)
                .setNegativeButton(context.getText(R.string.cancel), null).show();

        alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String,String> paramsMap=new HashMap<>();
                paramsMap.put("temperature_NO1",et_temperature.getText().toString());
                paramsMap.put("CO2_NO1",et_CO2_concentration.getText().toString());
                dialogListener.onClick(alertDialog,DialogInterface.BUTTON_POSITIVE,paramsMap);
            }
        });

        alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogListener.onClick(alertDialog,DialogInterface.BUTTON_NEGATIVE,null);
            }
        });

//        Dialog dialog = builder.create();
//        dialog.show();
//        dialog.getWindow().setContentView(view);
    }
}
